extern crate movie_lib;
use movie_lib::movie;

mod movies;

fn main() {
    let text1: &str = "简单教程";
    let text2: &'static str = "复杂教程";
    println!("{}", text1);
    println!("{}", text2);
    let mut text3: String = String::from("简单教程");
    println!("{}", text3);
    text3 = "复杂教程".to_string();
    println!("{}", text3);
    println!("Hello, world!");

    //这就是switch
    let state_code: &str = "MH";
    let state: &str = match state_code {
        "MH" => {
            println!("Found match for MH");
            "Maharashtra"
        }
        "KL" => "Kerala",
        "KA" => "Karnadaka",
        "GA" => "Goa",
        _ => "Unknown",
    };
    println!("{}", state);

    for x in 1..11 {
        println!("{}", x);
    }

    let answer = console("我爱你");
    println!("{}", answer);

    to_zero(&mut 1);

    let tuple = (-325, 4.9, 22);
    println!("{:?}", tuple);

    let arr = [10, 20, 30, 40];
    println!("{:?}", arr);
    println!("{:?}", arr[1]);
    println!("{}", arr.len());

    let mut v = vec![1, 2, 3];
    print_vector(&mut v);
    println!("{:?}", v);

    let p1 = Point::get_instance(10, 10);
    p1.display();
    let p2 = Point::get_instance(20, 20);
    p2.display();

    let selected1 = Fruits::Banana;
    let selected2 = Fruits::Pear;
    let selected3 = Fruits::Mandarin;
    let selected4 = Fruits::Eggplant;
    println!(
        "{:?}-{:?}-{:?}-{:?}",
        selected1, selected2, selected3, selected4
    );

    movies::movies::play("内部lib".to_string());
    movie::play("外部lib".to_string());
}

fn console(input: &str) -> &str {
    println!("这里是函数：{}", input);
    return "我也爱你";
}

fn to_zero(num: &mut i32) {
    *num = 0;
    println!("{}", num);
}

fn print_vector(x: &mut Vec<i32>) {
    println!("{:?}", x);
    *x = vec![4, 5, 6];
}

struct Point {
    x: i32,
    y: i32,
}

impl Point {
    fn get_instance(x: i32, y: i32) -> Point {
        Point { x: x, y: y }
    }
    fn display(&self) {
        println!("x ={}     y={}", self.x, self.y);
    }
}

#[derive(Debug)]
enum Fruits {
    Banana,   // 香蕉
    Pear,     // 梨
    Mandarin, // 橘子
    Eggplant, // 茄子
}
